package com.itheima.web;

import com.itheima.pojo.Book;
import com.itheima.service.BookService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet("/queryAllServlet")
public class QueryAllServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //去除中文乱码
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");


        //通过业务类对象拿到所有书籍的信息
        List<Book> allBooks = new BookService().findAllBooks();

        //将数据存到域对象中,转发给jsp页面
        request.setAttribute("books",allBooks);
        //转发jsp页面
        request.getRequestDispatcher("/bookList.jsp").forward(request,response);


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
